#include <iostream>
#include "bitree.cpp"
#define NEW_NODE (BiTNode *)malloc(sizeof(BiTNode))

using namespace std;

Status print(TElemType e)
{
	printf("%d ", e);
	return OK;
}

void traverse(BiTree T)
{
	Status st;
	cout << "Pre: ";
	st = T.PreOrderTraverse(print);
	if(st != OK)
		return;
	cout << endl << "In: ";
	st = T.InOrderTraverse(print);
	if(st != OK)
		return;
	cout << endl << "Post: ";
	st = T.PostOrderTraverse(print);
	if(st != OK)
		return;
	cout << endl << "Level: ";
	st = T.LevelOrderTraverse(print);
	if(st != OK)
		return;
	cout << endl;
}

int main()
{
	BiTree tree;
	BiTNode *temp;
	Status st;

	temp = NEW_NODE;
	temp->data = 1;
	temp->lchild = temp->rchild = temp->parent = NULL;
	st = tree.InsertChild(NULL, 0, temp);

	temp = NEW_NODE;
	temp->data = 2;
	temp->lchild = temp->rchild = temp->parent = NULL;
	st = tree.InsertChild(tree.Root(), 0, temp);

	temp = NEW_NODE;
	temp->data = 3;
	temp->lchild = temp->rchild = temp->parent = NULL;
	st = tree.InsertChild(tree.Root(), 1, temp);

	traverse(tree);
	BiTNode *left, *right;
	left = tree.LeftChild(tree.Root());
	right = tree.RightChild(tree.Root());
	
	temp = NEW_NODE;
	temp->data = 4;
	temp->lchild = temp->rchild = temp->parent = NULL;
	tree.InsertChild(right, 0, temp);
	traverse(tree);

	temp = NEW_NODE;
	temp->data = 5;
	temp->lchild = temp->rchild = temp->parent = NULL;
	tree.InsertChild(right, 1, temp);
	traverse(tree);
	cout << endl;

	tree.DeleteChild(tree.Root(), 1);
	traverse(tree);
	return 0;
}
/*
1
|\
2 3
  |\
  4 5
就这样吧- -
*/